﻿using AutoMapper;
using MediatR;
using S.EarTag.API.Mediator.MediatorCommand;
using S.EarTag.Domain.Model;
using S.EarTag.Infrastructure.Repository.Interface.IEarTagRepository;

namespace S.EarTag.API.Mediator.MediatorCommandHandler
{
    public class EarTagUpdateCommandHandler : IRequestHandler<EarTagUpdateCommand, bool>
    {
        private readonly IEarTagModelRepository _earTagModelRepository;
        private readonly IMapper _mapper;
        public EarTagUpdateCommandHandler(IEarTagModelRepository earTagModelRepository,IMapper mapper)
        {
            _earTagModelRepository=earTagModelRepository;
            _mapper=mapper;
        }
        /// <summary>
        /// 修改耳标管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(EarTagUpdateCommand request, CancellationToken cancellationToken)
        {
            return await _earTagModelRepository.UpdateAsync(_mapper.Map<EarTagModel>(request));
            //return await _earTagModelRepository.UpdateAsync(new EarTagModel
            //{
            //    EarTagId = request.EarTagId,
            //    WarehousingDate = request.WarehousingDate,
            //    BirthState = request.BirthState,
            //    BreedItem = request.BreedItem,
            //    EarTag = request.EarTag,
            //    UseState = request.UseState,
            //    CreateBy = request.CreateBy,
            //    CreateDate = request.CreateDate,
            //    UpdateBy = request.UpdateBy,
            //    UpdateDate = request.UpdateDate,
            //});
        }
    }
}
